<template>
  <div class="flexContent">
    <div class="add">
      <el-button class="addBtn" v-has="'goods_add'" @click="returnFn">返回</el-button>
    </div>
    <div class="table" id="tableBox" v-height>
      <div style="flex:1;">
        <vxe-table :column-config="{ resizable: true }" border class="tablebox" ref="xTable1"
          :row-config="{ isHover: true }" :scroll-y="{ enabled: true, gt: 21 }" style="width: 100%" height="650"
          size="medium" align="center">
          <vxe-column type="seq" width="80" title="序号" />

          <vxe-column field="commodityName" title="商品名称"
            :min-width="elTableAdaptationWidth('commodityName', scmOutBoundList)" />

          <vxe-column field="firstCode" v-if="type == '0'" title="商品条码"
            :min-width="elTableAdaptationWidth('firstCode', scmOutBoundList)" />
          <vxe-column field="batchNumber" title="批次号" width="160" v-if="type == '0'" />
          <vxe-column field="warehouseName" title="出库仓库" width="150" v-if="type == '0'" />
          <vxe-column field="storeName" title="点采来源" width="150" />
          <vxe-column field="procureCount" title="出库数量" min-width="120" v-if="type == '0'" />
          <vxe-column field="outWeight" title="出库数量(KG)" min-width="120" v-if="type == '1'" />
          <vxe-column field="outboundPrice" title="出仓价" min-width="120" />
          <vxe-column field="money" title="出仓金额" min-width="120" />
          <vxe-column field="createTime" title="出库时间" width="150">
            <template v-slot="{ row }">
              <span>{{ row.createTime | parseTime }}</span>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
      <div class="paginationBox">
        <el-pagination :current-page="page.pageNum" background :page-sizes="$pageSizes" :page-size="page.pageSize"
          layout="total,-> , sizes, prev, pager, next, jumper" :total="page.total" @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </div>
  </div>
</template>

<script>
import { getSupplierProductInReportDetail, getSupplierNonstandardProductInReportDetail } from "@/api/report";
export default {
  name: "scmOutRoundReportDetail",
  data() {
    return {
      sForm: {
        supplierId: '',
        maxDate: '',
        minDate: '',
        commodityId: ''
      },
      type: '',
      date: '',
      scmOutBoundList: [],
      firstSupplierList: [],
      isSearch: false,
      page: {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      },
      allDataArr: [],
    };
  },
  created() {
    this.type = this.$route.query.type
    this.sForm.supplierId = this.$route.query.supplierId
    this.sForm.maxDate = this.$route.query.maxDate
    this.sForm.minDate = this.$route.query.minDate
    this.sForm.commodityId = this.$route.query.commodityId
    if (this.type == '0') {
      this.getSupplierProductInReportDetail();
    } else {
      this.getSupplierNonstandardProductInReportDetail();
    }
  },
  methods: {
    async getSupplierProductInReportDetail() {
      const res = await getSupplierProductInReportDetail({
        ...this.page,
        ...this.sForm
      });
      if (res.code === 200) {
        console.log(res);
        const result = res.data;
        this.scmOutBoundList = result.list;
        this.page.pageSize = result.pageSize;
        this.page.pageNum = result.pageNum;
        this.page.total = result.total;
        console.log("shopList", this.scmOutBoundList);
        const $table = this.$refs.xTable1
        $table.loadData(this.scmOutBoundList);
      } else {
        // this.$message.error(res.message);
      }
    },
    async getSupplierNonstandardProductInReportDetail() {
      const res = await getSupplierNonstandardProductInReportDetail({
        ...this.page,
        ...this.sForm
      });
      if (res.code === 200) {
        console.log(res);
        const result = res.data;
        this.scmOutBoundList = result.list;
        this.page.pageSize = result.pageSize;
        this.page.pageNum = result.pageNum;
        this.page.total = result.total;
        console.log("shopList", this.scmOutBoundList);
        const $table = this.$refs.xTable1
        $table.loadData(this.scmOutBoundList);
      } else {
        // this.$message.error(res.message);
      }
    },
    // 获取条数改变
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.page.pageNum = 1;
      console.log(`每页 ${val} 条`);
      if (this.type == '0') {
        this.getSupplierProductInReportDetail();
      } else {
        this.getSupplierNonstandardProductInReportDetail();
      }
    },
    // 获取页数改变
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page.pageNum = val;
      if (this.type == '0') {
        this.getSupplierProductInReportDetail();
      } else {
        this.getSupplierNonstandardProductInReportDetail();
      }
    },
    returnFn() {
      this.closeTag('scmOutRoundReport');
    }
  },
};
</script>

<style lang="scss" scoped>
.txtBox {
  padding-left: 20px;
  margin-bottom: 30px;

}

.btnBOX {
  text-align: center;
}
</style>
